package com.wallet.provider.controller;

import com.wallet.common.vo.PageResult;
import com.wallet.provider.model.Role;
import com.wallet.provider.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class RoleController {

    @Autowired
    private RoleService roleService;

    /**
     * 分页查询角色
     * @param keywords
     * @param pageNum
     * @param pageSize
     * @param orderName
     * @param orderType
     * @return
     */
    @RequestMapping(value = "/getRoleList", method = RequestMethod.POST)
    public PageResult<Role> getRoleList(String keywords, int pageNum, int pageSize, String orderName, String orderType){
        return  roleService.getRoleList(keywords,pageNum,pageSize,orderName,orderType);
    }

    /**
     * 添加角色
     * @param role
     */
    @RequestMapping(value = "/addRole", method = RequestMethod.POST)
    public Boolean addRole(Role role){
        return roleService.addRole(role);
    }

    /**
     * 根据id删除角色
     * @param ids
     * @return
     */
    @RequestMapping(value = "/deleteRole", method = RequestMethod.POST)
    public Boolean deleteRole(String ids){
        return roleService.deleteRole(ids);
    }

    /**
     * 根据id查询角色
     * @param id
     * @return
     */
    @RequestMapping(value = "/getRoleById", method = RequestMethod.GET)
    public Role getRoleById(Long id){
        return roleService.getRoleById(id);
    }

    /**
     * 根据userId查询角色
     * @param id
     * @return
     */
    @RequestMapping(value = "/getRoleByUserId", method = RequestMethod.GET)
    public List<Role> getRoleByUserId(Long id){
        return roleService.getRoleByUserId(id);
    }

    /**
     * 修改角色
     * @param role
     * @return
     */
    @RequestMapping(value = "/updateRole", method = RequestMethod.POST)
    public Boolean updateRole(Role role){
        return roleService.updateRole(role);
    }

    @RequestMapping(value = "/getAllRoleList", method = RequestMethod.GET)
    public List<Role> getAllRoleList(){
        return roleService.getAllRoleList();
    }
}
